//
//  DrivesDayView.m
//  carcareIOS
//
//  Created by ileo on 16/6/28.
//  Copyright © 2016年 chezheng. All rights reserved.
//

#import "DrivesDayView.h"


@interface DrivesDayView ()

@property (nonatomic, strong) UILabel *dayL;
@property (nonatomic, strong) UIView *pointV;
@property (nonatomic, strong) UIView *circleV;
@property (nonatomic, strong) UIButton *button;

@end

@implementation DrivesDayView

@synthesize dateComponents = _dateComponents;
@synthesize Click = _Click;

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor = [UIColor whiteColor];
        self.circleV = [[[UIView viewWithFrame:CGRectMake(0, 0, 36, 36)] resetCornerRadius:18] setupOnView:self];
        self.dayL = [[[UILabel labelWithFrame:CGRectMake(0, 0, 40, 40) font:FONT_Num(16) text:nil textColor:COLOR_HEXSTRING(@"#424242")] labelResetTextAlignment:NSTextAlignmentCenter] setupOnView:self];
        self.pointV = [[[UIView viewWithFrame:CGRectMake(0, 0, 4, 4)] resetCornerRadius:2] setupOnView:self];
        __weak __typeof(self) wself = self;
        self.button = [[UIButton buttonEmptyWithFrame:CGRectMake(0, 0, 40, 40) click:^{
            if (wself.Click) {
                wself.Click(wself.dateComponents);
            }
        }] setupOnView:self];
    }
    return self;
}

-(void)setFrame:(CGRect)frame{
    [super setFrame:frame];
    self.dayL.center = CGPointMake(self.boundsCenter.x, self.boundsCenter.y - 2);
    self.circleV.center = CGPointMake(self.dayL.centerX, self.dayL.centerY + 2);
    self.pointV.center = CGPointMake(self.dayL.centerX, self.dayL.bottom - 6);
    self.button.frame = self.bounds;
}

-(void)setupDataComponents:(NSDateComponents *)dateComponents drivesDayModel:(DrivesDayModel *)drivesDayModel{
    self.dateComponents = dateComponents;
    self.dayL.text = drivesDayModel.isToday ? @"今" : [NSString stringWithFormat:@"%zd",dateComponents.day];
    self.dayL.textColor = (drivesDayModel.isThisMonth || drivesDayModel.isShowWeek) ? (drivesDayModel.isChoiced ? [UIColor whiteColor] : (drivesDayModel.isNotData ? COLOR_HEXSTRING(@"#9b9b9b") : COLOR_HEXSTRING(@"#424242"))) : COLOR_HEXSTRING(@"#d9d9d9");
    self.pointV.backgroundColor = drivesDayModel.isChoiced ? [UIColor whiteColor] : COLOR_HEXSTRING(@"#c8c8c8");
    self.pointV.hidden = !drivesDayModel.isDrived;
    self.circleV.backgroundColor = drivesDayModel.isChoiced ? COLOR_HEXSTRING(@"#2090e6") : COLOR_HEXSTRING(@"#f0f0f0");
    self.circleV.hidden = !(drivesDayModel.isChoiced || drivesDayModel.isToday);
    self.button.enabled = !drivesDayModel.isNotData && (drivesDayModel.isThisMonth || drivesDayModel.isShowWeek);
}

@end



